import requests
import json
import cron.models as cron_models
def sms(**kwargs):
    task_name = kwargs['task_name']

    ##params为短信内容和联系人
    params={}
    params['reciever'] = kwargs['reciever']
    params['message'] = kwargs['message']
    url = "http://12.18.0.18:8081/smsmessage/?key=sendMsg@Ghs2020"
    #params = {"reciever":"13810087640","message":"111"}
    #发送短信
    res = requests.get(url=url,params=params)
    #获取短信发送状态0或1
    sms_status = json.loads(res.text)['result']
    #获取短信发送返回值
    sms_text = json.loads(res.text)
    #插入短信发送信息表
    cron_models.oratk_cron_sms_send.objects.create(task_name=task_name,sms_conent=kwargs['reciever'],sms_contact=kwargs['message'],sms_status=sms_status,sms_code=res,sms_text=sms_text)
    ##print是work执行时,打印的结果
    if json.loads(res.text)['result'] != 1:
       print("success")
    else:
       print("fail")
